using System;
using System.ComponentModel;
using System.Security.Permissions;
using System.Web;
using PickGold.Charting.Utilities;

namespace PickGold.Charting
{
	[DefaultProperty("Position")]
	[SRDescription("DescriptionAttributeAxisDataView_AxisDataView")]
	[AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	public class AxisScaleView
	{
		private bool _ignoreValidation;
		private double _position;
		private double _size;
		private DateTimeIntervalType _sizeType;
		internal Axis axis;

		public AxisScaleView()
		{
			this._position = double.NaN;
			this._size = double.NaN;
			this.axis = null;
		}

		internal AxisScaleView(Axis axis)
		{
			this._position = double.NaN;
			this._size = double.NaN;
			this.axis = axis;
		}

		[SRCategory("CategoryAttributeAxisView"), SerializationVisibility(SerializationVisibility.Hidden), Bindable(false), Browsable(false), SRDescription("DescriptionAttributeAxisDataView_IsZoomed"), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public bool IsZoomed
		{
			get
			{
				return ((!double.IsNaN(this.Size) && (this.Size != 0.0)) && !double.IsNaN(this.Position));
			}
		}

		[Bindable(true), SRCategory("CategoryAttributeAxisView"), ParenthesizePropertyName(true), DefaultValue(double.NaN), SRDescription("DescriptionAttributeAxisDataView_Position"), TypeConverter(typeof(DoubleDateNanValueConverter))]
		public double Position
		{
			get
			{
				if (((this.axis != null) && (this.axis.ChartArea != null)) && this.axis.ChartArea.chartAreaIsCurcular)
				{
					return double.NaN;
				}
				return this._position;
			}
			set
			{
				if ((((this.axis == null) || (this.axis.ChartArea == null)) || !this.axis.ChartArea.chartAreaIsCurcular) && (this._position != value))
				{
					this._position = value;
					if ((((this.axis != null) && (this.axis.ChartArea != null)) && ((this.axis.Common != null) && (this.axis.Common.ChartPicture != null))) && !this.axis.ChartArea.alignmentInProcess)
					{
						AreaAlignmentOrientations orientation = ((this.axis.axisType == AxisName.X) || (this.axis.axisType == AxisName.X2)) ? AreaAlignmentOrientations.Vertical : AreaAlignmentOrientations.Horizontal;
						this.axis.Common.ChartPicture.AlignChartAreasAxesView(this.axis.ChartArea, orientation);
					}
					if (!this._ignoreValidation && (this.axis != null))
					{
						this.axis.Invalidate();
					}
				}
			}
		}

		[SRCategory("CategoryAttributeAxisView"), ParenthesizePropertyName(true), Bindable(true), DefaultValue(double.NaN), SRDescription("DescriptionAttributeAxisDataView_Size"), TypeConverter(typeof(DoubleNanValueConverter))]
		public double Size
		{
			get
			{
				if (((this.axis != null) && (this.axis.ChartArea != null)) && this.axis.ChartArea.chartAreaIsCurcular)
				{
					return double.NaN;
				}
				return this._size;
			}
			set
			{
				if ((((this.axis == null) || (this.axis.ChartArea == null)) || !this.axis.ChartArea.chartAreaIsCurcular) && (this._size != value))
				{
					this._size = value;
					if ((((this.axis != null) && (this.axis.ChartArea != null)) && ((this.axis.Common != null) && (this.axis.Common.ChartPicture != null))) && !this.axis.ChartArea.alignmentInProcess)
					{
						AreaAlignmentOrientations orientation = ((this.axis.axisType == AxisName.X) || (this.axis.axisType == AxisName.X2)) ? AreaAlignmentOrientations.Vertical : AreaAlignmentOrientations.Horizontal;
						this.axis.Common.ChartPicture.AlignChartAreasAxesView(this.axis.ChartArea, orientation);
					}
					if (!this._ignoreValidation && (this.axis != null))
					{
						this.axis.Invalidate();
					}
				}
			}
		}

		[Bindable(true), ParenthesizePropertyName(true), SRCategory("CategoryAttributeAxisView"), DefaultValue(0), SRDescription("DescriptionAttributeAxisDataView_SizeType")]
		public DateTimeIntervalType SizeType
		{
			get
			{
				return this._sizeType;
			}
			set
			{
				if (this._sizeType != value)
				{
					this._sizeType = (value != DateTimeIntervalType.NotSet) ? value : DateTimeIntervalType.Auto;
					if ((((this.axis != null) && (this.axis.ChartArea != null)) && ((this.axis.Common != null) && (this.axis.Common.ChartPicture != null))) && !this.axis.ChartArea.alignmentInProcess)
					{
						AreaAlignmentOrientations orientation = ((this.axis.axisType == AxisName.X) || (this.axis.axisType == AxisName.X2)) ? AreaAlignmentOrientations.Vertical : AreaAlignmentOrientations.Horizontal;
						this.axis.Common.ChartPicture.AlignChartAreasAxesView(this.axis.ChartArea, orientation);
					}
					if (!this._ignoreValidation && (this.axis != null))
					{
						this.axis.Invalidate();
					}
				}
			}
		}

		[Browsable(false), SerializationVisibility(SerializationVisibility.Hidden)]
		public double ViewMaximum
		{
			get
			{
				if (!double.IsNaN(this.Size))
				{
					if (!double.IsNaN(this.Position))
					{
						double num = ChartHelper.GetIntervalSize(this.Position, this.Size, this.SizeType);
						if ((this.Position + num) >= this.axis.maximum)
						{
							return (this.Position + num);
						}
						return ((this.Position + num) + this.axis.marginView);
					}
					this.Position = this.axis.Minimum;
				}
				return this.axis.maximum;
			}
		}

		[Browsable(false)]
		[SerializationVisibility(SerializationVisibility.Hidden)]
		public double ViewMinimum
		{
			get
			{
				if (!double.IsNaN(this.Size))
				{
					if (!double.IsNaN(this.Position))
					{
						if (this.Position <= this.axis.minimum)
						{
							return this.Position;
						}
						return (this.Position - this.axis.marginView);
					}
					this.Position = this.axis.Minimum;
				}
				return this.axis.minimum;
			}
		}
	}
}

